home *** CD-ROM | disk | FTP | other *** search
/ CrystalVision Software Se… Wiki Wonder - Wikipedia / CrystalVision Software Services 703: The Wiki Wonder - Wikipedia.iso / 0703 / Business / CodeX Apps / CodeX.exe / CodeX / html / lib / General.lib.php < prev    next >
Encoding:
PHP Script  |  2006-11-12  |  5.5 KB  |  247 lines

  1. <?php
  2. /*************************************************************
  3.  
  4.                 CodeX Project System Library
  5.  
  6.                         General Library
  7.  
  8. *************************************************************/
  9. //----------------------------------- Profile Functions ----------------------------------------------
  10. function LoadSettings($PluginName)    //loads specific plugin setting, returns setting array.
  11. {
  12.     global $pluginDIR;
  13.     $PluginName=SecurityFormat($PluginName);
  14.     if(!file_exists("$pluginDIR/$PluginName.Settings.php")) return false;
  15.     //$SettingsFile="$basedir/$PluginName.Settings.php";
  16.     
  17.     $File=file("$pluginDIR/$PluginName.Settings.php");
  18.     $Settings=unserialize(trim($File[1]));
  19.     if(!is_array($Settings)) return false;
  20.     return $Settings;
  21. }
  22.  
  23. function SaveSettings($PluginName,$NewSettings)
  24. {
  25.     global $pluginDIR;
  26.     $PluginName=SecurityFormat($PluginName);
  27.     if(!is_array($NewSettings)) return false;
  28.     $File=@file($pluginDIR."/".$PluginName.".Settings.php");
  29.     $Settings=unserialize(trim($File[1]));
  30.     if(!is_array($Settings))    //create new
  31.     {
  32.         $Settings=$NewSettings;
  33.     }
  34.     else
  35.     {
  36.         reset($NewSettings);
  37.         while(list($FieldName,$FieldValue)=each($NewSettings))
  38.         {
  39.             if(is_array($NewSettings[$FieldName]))
  40.             {
  41.                 if(!is_array($Settings[$FieldName])) $Settings[$FieldName]=array();
  42.                 $Settings[$FieldName]=array_merge($Settings[$FieldName],$NewSettings[$FieldName]);
  43.             }
  44.             else
  45.             {
  46.                 if($FieldValue==null)
  47.                 {
  48.                     unset($Settings[$FieldName]);
  49.                 }
  50.                 else
  51.                 {
  52.                     $Settings[$FieldName]=$FieldValue;
  53.                 }
  54.             }
  55.         }
  56.     }
  57.     
  58.     $fp=fopen($pluginDIR."/".$PluginName.".Settings.php","w+");
  59.     fputs($fp,"<?phpexit(\"Access Denied.\");?>\n");
  60.     fputs($fp,str_replace("\n","",serialize($Settings))."\n");
  61.     fclose($fp);
  62.     
  63.     return $Settings;
  64. }
  65.  
  66. function LoadUserPreference($TargetID="")
  67. {
  68.     global $AccountInfo, $basedir;
  69.     if(!$TargetID)
  70.     {
  71.         if(!$AccountInfo["DataAddress"])    return false;
  72.         $TargetID=$AccountInfo["DataAddress"];
  73.     }
  74.     
  75.     /*
  76.     if(file_exists($basedir."/data/UserPreferences/".$AccountInfo["UserName"].".pref.php"))
  77.     {
  78.         rename($basedir."/data/UserPreferences/".$AccountInfo["UserName"].".pref.php",$basedir."/data/UserPreferences/".$AccountInfo["DataAddress"].".pref.php");
  79.     }*/
  80.     
  81.     if(file_exists($basedir."/data/UserPreferences/".$TargetID.".pref.php"))
  82.     {
  83.         $Config=file($basedir."/data/UserPreferences/".$TargetID.".pref.php");
  84.         return unserialize(trim($Config[1]));
  85.     }
  86.     return false;
  87. }
  88.  
  89. function SaveUserPreference($Settings)
  90. {
  91.     global $basedir, $AccountInfo;
  92.     if(!$AccountInfo["DataAddress"])    return false;
  93.     if(!is_array($Settings)) return false;
  94.     
  95.     if(!is_dir($basedir."/data/UserPreferences/"))
  96.     {
  97.         mkdir($basedir."/data/UserPreferences/");
  98.         chmod($basedir."/data/UserPreferences/", 0777);
  99.     }
  100.     
  101.     $fp=fopen($basedir."/data/UserPreferences/".$AccountInfo["DataAddress"].".pref.php","w+");
  102.     fputs($fp,"<?phpexit(\"Access Denied.\");?>\n");
  103.     fputs($fp,str_replace("\n","",serialize($Settings))."\n");
  104.     fclose($fp);
  105.     
  106.     return true;
  107. }
  108.  
  109. function SecurityFormat($str,$level=3)
  110. {
  111.     $str=trim($str);
  112.     switch($level)
  113.     {
  114.         case 1: //for data items with length limitation.
  115.             $str=trim(str_replace("\n","",$str));
  116.             if(strlen($str)>16) $str=substr($str,0,16);
  117.             break;
  118.         case 2: //for digit validation
  119.             if(!(trim($str)>=0))
  120.             {
  121.                 $str=0;
  122.             }
  123.             break;
  124.         case 5: //for dataitem operation filter
  125.             $str=str_replace("\\","",$str);
  126.             $str=str_replace("\n","",$str);
  127.             break;
  128.         case 3: //for file operation filter
  129.             $str=str_replace("\\","",$str);
  130.             $str=str_replace("/","",$str);
  131.             $str=str_replace("\n","",$str);
  132.             break;
  133.         case 4: //for file data filter
  134.             $str=str_replace("\\","@",$str);
  135.             $str=str_replace("\n","",$str);
  136.             break;
  137.     }
  138.     return $str;
  139. }
  140.  
  141. function Template($TemplateFile, $Translator)
  142. {
  143.     return strtr(file_get_contents($TemplateFile),$Translator);
  144. }
  145.  
  146. function CSSGenerator($CSSPack)
  147. {
  148.     if(!is_array($CSSPack))    return false;
  149.     global $ThemePack;
  150.     foreach($CSSPack as $FileName)
  151.     {
  152.         $CSSCode.="<link rel='stylesheet' type='text/css' href='/themes/".$GLOBALS["ThemePack"].$FileName."' />\n";
  153.     }
  154.     return $CSSCode;
  155. }
  156.  
  157. function UpdateBuddyStatus($Action="Automatic")
  158. {
  159.     global $AccountInfo, $basedir;
  160.     $Users=NULL;
  161.     
  162.     $nowlist = @file($basedir."/data/onlineusers.ini");
  163.     $found=0;
  164.     
  165.     if(count($nowlist))
  166.     {
  167.         for($i=0;$i<count($nowlist);$i++)
  168.         {
  169.             $OnlineUser=unserialize(trim($nowlist[$i]));
  170.             
  171.             if($OnlineUser["AccountID"]==$AccountInfo["DataAddress"])
  172.             {
  173.                 $OnlineUser[$Action]=time();
  174.                 $nowlist[$i]=serialize($OnlineUser);
  175.                 $found++;
  176.             }
  177.             else
  178.             {
  179.                 if((time()-$OnlineUser["Automatic"])>=300)
  180.                 {
  181.                     $nowlist[$i]="";
  182.                 }
  183.             }
  184.         }
  185.     }
  186.     if(!$found)
  187.     {
  188.         $OnlineUser["AccountID"]=$AccountInfo["DataAddress"];
  189.         $OnlineUser["Automatic"]=time();
  190.         $nowlist[]=serialize($OnlineUser);
  191.     }
  192.     
  193.     $fp2=fopen($basedir."/data/onlineusers.ini","w+");
  194.     foreach($nowlist as $content)
  195.     {
  196.         if($content=trim($content))
  197.         {
  198.             fputs($fp2,$content."\n");
  199.         }
  200.     }
  201.     fclose($fp2);
  202.     return true;
  203. }
  204.  
  205. function GetBuddyStatus()
  206. {
  207.     global $AccountInfo, $basedir;
  208.     $Status=array();
  209.     $nowlist = @file($basedir."/data/onlineusers.ini");
  210.     if(count($nowlist))
  211.     {
  212.         foreach($nowlist as $content)
  213.         {
  214.             $Item=unserialize($content);
  215.             if(!is_array($Item))    continue;
  216.             
  217.             if((time()-$Item["Manual"])>120)
  218.                 $tStatus="Busy";
  219.             else
  220.                 $tStatus="Online";
  221.             $Status[$Item["AccountID"]]=$tStatus;
  222.         }
  223.     }
  224.     return $Status;
  225. }
  226.  
  227. /*
  228. Text Files list
  229. */
  230. $mime_text[]="html";
  231. $mime_text[]="htm";
  232. $mime_text[]="asp";
  233. $mime_text[]="php";
  234. $mime_text[]="php3";
  235. $mime_text[]="py";
  236. $mime_text[]="cgi";
  237. $mime_text[]="jsp";
  238.  
  239. $mime_text[]="c";
  240. $mime_text[]="cpp";
  241. $mime_text[]="asm";
  242.  
  243. $mime_text[]="txt";
  244. $mime_text[]="ini";
  245. $mime_text[]="inf";
  246.  
  247. ?>